<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="myCanvas">

    </canvas>
    <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        //矩形
        ctx.beginPath();
        ctx.fillStyle = "#FF0000";
        let x =0;
        setInterval(() => {
            ctx.clearRect(0,0,c.width,c.height);
            x+=1;
           ctx.fillRect(x, 100, 50,50); 
            
        },1000/60);
        
        
    </script>
</body>

</html>